<?php
    include_once "common.inc";
    $type = $_GET['type'];
    if (!is_numeric($type) || !($type >= 0 && $type < 4))
        $type = 0;
    $factors = loadFactors($type);
    sort($factors, SORT_LOCALE_STRING);
    include "heading.inc";
?>
<table class="main_tbl">
    <tr>
        <td class="left_col">
        </td>
        <td>
            <?php include "menu.inc"; ?>
        </td>
    </tr>
    <tr>
        <td style="vertical-align: top;">
            <ul class="nav2">
            <?php
                $subs = array("Сильные стороны", "Слабые стороны", "Возможности", "Угрозы");
                for ($i = 0; $i < 4; $i++) {
            ?>
                <li>
                    <a href="swots.php?type=<?php echo $i; ?>">
                        <span class="<?php if ($type == $i) echo "active"; ?>item">
                            <?php echo $subs[$i]; ?>
                        </span>
                    </a>
                    <?php if ($i < 3) echo "→"; ?>
                </li>
            <?php
                }
            ?>
            </ul>
        </td>
        <td>
            <form action="save.php" method="POST">
                <input type="hidden" name="gid" value="<?php echo $gid; ?>"/>
                <input type="hidden" name="to" value="swots"/>
                <input type="hidden" name="type" value="<?php echo $type; ?>"/>
                <h3><?php echo htmlspecialchars($game['caption'], ENT_QUOTES, 'UTF-8');?></h3>
                <h3>Ввод SWOT-матрицы</h3>
                <h1><?php echo $subs[$type]; ?></h1>
                <table>
                    <tr>
                        <td>
                            Название
                        </td>
                        <td>
                            Значима?
                        </td>
                        <td colspan="2">
                            Выбор названий из глобальной базы
                        </td>
                    </tr>
                    <?php for ($i = 0; $i < $maxCount; $i++) { ?>
                    <tr id="row_<?php echo $i; ?>" <?php if ($i > $values['counts'][$type]) { ?>style="display: none;"<?php } ?>>
                        <td>
                            <input id="caption_<?php echo $i; ?>" type="text" style="width: 300px;" name="caption_<?php echo $i; ?>"
                                    value="<?php echo htmlspecialchars($values['swots'][$type][$i]['caption'], ENT_QUOTES, "UTF-8"); ?>"/>
                        </td>
                        <td>
                            <select name="valuability_<?php echo $i; ?>">
                                <?php for ($j = 0; $j < 5; $j++) { ?>
                                    <option value="<?php echo $j; ?>"
                                        <?php if ($j == 2 && $i >= $values['counts'][$type] || $j == $values['swots'][$type][$i]['valuability'])
                                                echo "selected"; ?>>
                                        <?php echo $valuabilities[$j]; ?></option>
                                <?php } ?>
                            </select>
                        </td>
                        <td>
                            <input type="button" value="←"
                                    onclick="document.getElementById('caption_<?php echo $i; ?>').value = document.getElementById('base_factor').value" />
                        </td>
                        <?php if ($i == 0) { ?>
                        <td rowspan="<?php echo $maxCount; ?>">
                            <select id="base_factor" size="10">
                                <?php for ($j = 0; $j < count($factors); $j++) { ?>
                                <option value="<?php echo htmlspecialchars($factors[$j], ENT_QUOTES, 'UTF-8'); ?>">
                                    <?php echo htmlspecialchars($factors[$j], ENT_QUOTES, 'UTF-8'); ?>
                                </option>
                                <?php } ?>
                            </select>
                        </td>
                        <?php } ?>
                    </tr>
                    <?php } ?>
                    <script type="text/javascript">
                        var count = <?php echo $maxCount; ?>;
                        var pmi = -100;
                        function renewRows() {
                            var maxIndex = <?php echo $minCount - 2; ?>;
                            for (i = 0; i < count; i++) {
                                var elem = document.getElementById('caption_' + i);
                                if (elem.value != "")
                                    maxIndex = i;
                            }
                            if (maxIndex != pmi) {
                                for (i = 0; i < count && i < maxIndex + 2; i++)
                                    document.getElementById('row_' + i).style.display = 'table-row';
                                for (; i < count; i++)
                                    document.getElementById('row_' + i).style.display = 'none';
                                pmi = maxIndex;
                            }
                            setTimeout("renewRows()", 100);
                        }
                        setTimeout("renewRows()", 1000);
                    </script>
                </table>
                Комментарии:<br/>
                <textarea class="comments" name="comments"><?php echo htmlspecialchars($game['comments'], ENT_QUOTES, 'UTF-8'); ?></textarea>
                <br/>
                <input type=submit value="Сохранить"/>
            </form>
        </td>
    </tr>
</table>
<?php
    include "footer.inc";
?>
